<?php
require_once('ppComponent.class.php');
/**
* 
*/
class ppCompiller
{
	
	protected $_path;
	
	public function __construct($path)
	{
		$this->_path = $path;		
	}
	
	protected $_rootComponent;
	
	public function compile(){
		$doc = new DOMDocument();
		$doc->preserveWhiteSpace=false;
		$doc->load($this->_path);
		$children = $doc->childNodes;
		
		foreach ($children as $child) {
			var_dump($child->tagName);
			$this->_rootComponent = new ppComponent();
			$this->compileComponent($this->_rootComponent,$child);
		}
		return $this->_rootComponent;
	}
	
	protected function compileComponent($rootComponent,$domNode){
		//var_dump($domNode->tagName);
		if($domNode->childNodes->length>0){
			foreach($domNode->childNodes as $childNode){
				$component = ppComponent::create($childNode->tagName,$childNode->namespaceURI);
				$component->deserialize($childNode);
				$rootComponent->addChild($component);
				if($childNode->getAttribute('name')!=''){
					$this->_rootComponent->addNamedChild($component);
				}
				$this->compileComponent($component,$childNode);
			}
		}
	}
}